/*
 * @Author: asd 714740235@qq.com
 * @Date: 2024-12-28 20:18:34
 * @LastEditors: aggfb 714740235@qq.com
 * @LastEditTime: 2025-02-15 23:10:26
 * @FilePath: \wire_receiver_out_terminal\bsp\bsp_gpio.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: aggfb 714740235@qq.com
 * @Date: 2024-11-21 21:27:50
 * @LastEditors: aggfb 714740235@qq.com
 * @LastEditTime: 2024-12-21 18:27:03
 * @FilePath: \wire_receiver_box\bsp\bsp_gpio.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __BSP_GPIO_H
#define __BSP_GPIO_H

#include "gd32f4xx_gpio.h"
#include <stdint.h>   

// ADDR
#define ADDR0_PIN                         GPIO_PIN_3
#define ADDR0_GPIO_PORT                   GPIOA
#define ADDR1_PIN                         GPIO_PIN_4
#define ADDR1_GPIO_PORT                   GPIOA
#define ADDR2_PIN                         GPIO_PIN_5
#define ADDR2_GPIO_PORT                   GPIOA
#define ADDR3_PIN                         GPIO_PIN_6
#define ADDR3_GPIO_PORT                   GPIOA
#define ADDR4_PIN                         GPIO_PIN_7
#define ADDR4_GPIO_PORT                   GPIOC
#define ADDR5_PIN                         GPIO_PIN_8
#define ADDR5_GPIO_PORT                   GPIOC
#define ADDR6_PIN                         GPIO_PIN_9
#define ADDR6_GPIO_PORT                   GPIOC
#define ADDR7_PIN                         GPIO_PIN_10
#define ADDR7_GPIO_PORT                   GPIOC

// LED 
#define LED1_PIN                         GPIO_PIN_3
#define LED1_GPIO_PORT                   GPIOD
// 红
#define LED_RED_PIN                         GPIO_PIN_4
#define LED_RED_GPIO_PORT                   GPIOD
// 绿
#define LED_GREEN_PIN                         GPIO_PIN_2
#define LED_GREEN_GPIO_PORT                   GPIOD
// 扬声器
#define HORN_PIN                         GPIO_PIN_0
#define HORN_GPIO_PORT                   GPIOD
#define HORN(x)          gpio_bit_write(HORN_GPIO_PORT, HORN_PIN, (bit_status)(x));	

#define LED_GREEN(x)        gpio_bit_write(LED_GREEN_GPIO_PORT, LED_GREEN_PIN, (bit_status)(x));	
#define LED_RED(x)          gpio_bit_write(LED_RED_GPIO_PORT, LED_RED_PIN, (bit_status)(x));	

// 语音控制
#define VOICE_K1_PIN                         GPIO_PIN_8
#define VOICE_K1_GPIO_PORT                   GPIOD
// 收线已停止
#define VOICE_K2_PIN                         GPIO_PIN_9
#define VOICE_K2_GPIO_PORT                   GPIOD
#define VOICE_K2_PLAY(x) gpio_bit_write(VOICE_K2_GPIO_PORT, VOICE_K2_PIN, (bit_status)(x));	
// 请求换盘中
#define VOICE_K3_PIN                         GPIO_PIN_10
#define VOICE_K3_GPIO_PORT                   GPIOD
#define VOICE_K3_PLAY(x) gpio_bit_write(VOICE_K3_GPIO_PORT, VOICE_K3_PIN, (bit_status)(x));	
// 收线停止
#define VOICE_K4_PIN                         GPIO_PIN_11
#define VOICE_K4_GPIO_PORT                   GPIOD
#define VOICE_K4_PLAY(x) gpio_bit_write(VOICE_K4_GPIO_PORT, VOICE_K4_PIN, (bit_status)(x));	
// 允许换盘
#define VOICE_K5_PIN                         GPIO_PIN_12
#define VOICE_K5_GPIO_PORT                   GPIOD
#define VOICE_K5_PLAY(x) gpio_bit_write(VOICE_K5_GPIO_PORT, VOICE_K5_PIN, (bit_status)(x));	
// 请求换盘
#define VOICE_K6_PIN                         GPIO_PIN_13
#define VOICE_K6_GPIO_PORT                   GPIOD
#define VOICE_K6_PLAY(x) gpio_bit_write(VOICE_K6_GPIO_PORT, VOICE_K6_PIN, (bit_status)(x));	

// lora (m0,m1)
#define LORA_M0_PIN                      GPIO_PIN_11
#define LORA_M0_PORT                     GPIOA
#define LORA_M0(x)                       gpio_bit_write(LORA_M0_PORT, LORA_M0_PIN, (bit_status)(x));	

#define LORA_M1_PIN                      GPIO_PIN_12
#define LORA_M1_PORT                     GPIOA
#define LORA_M1(x)                       gpio_bit_write(LORA_M1_PORT, LORA_M1_PIN, (bit_status)(x));	

#define LORA_AUX_PIN                     GPIO_PIN_8
#define LORA_AUX_PORT                    GPIOA
#define LORA_AUX() gpio_input_bit_get(LORA_AUX_PORT, LORA_AUX_PIN)

#define CTRL_POWER_3V3_PIN                     GPIO_PIN_9
#define CTRL_POWER_3V3_PORT                    GPIOC
#define CTRL_POWER_3V3(x) gpio_bit_write(CTRL_POWER_3V3_PORT, CTRL_POWER_3V3_PIN, (bit_status)(x));	


typedef union bsp_gpio_addr
{
	uint8_t addr;
    struct {
    	uint8_t addr_0:1;
		uint8_t addr_1:1;
		uint8_t addr_2:1;
        uint8_t addr_3:1;
        uint8_t addr_4:1;
        uint8_t addr_5:1;
        uint8_t addr_6:1;
        uint8_t addr_7:1;
    };
} bsp_gpio_addr_t;

extern void bsp_gpio_init(void);
extern void bsp_gpio_led_toggle(uint8_t led_id);
extern uint8_t bsp_gpio_read_adrr(void);


#endif
